import { defineStore } from "pinia";
import { computed, ComputedRef, ref } from "vue";
import type { Ref } from "vue";
import type { Order, Summary } from "@/types/orderTypes/orderTypes.ts";
import { createOrderAPI } from "@/api/orderApi/orderApi.ts";
import { ShopCart } from "@/types/shopCartTypes/shopCartTypes.ts";
import { UserAddress } from "@/types/detailTypes/detailTypes.ts";

const useOrderStore = defineStore("orderStore", () => {
   const orderInfo: Ref<Order> = ref<Order>({} as Order);
   const goods:ComputedRef<any>=computed<any>(()=>orderInfo.value.goods)
   const summary:ComputedRef<Summary>=computed<Summary>(()=>orderInfo.value.summary)
   const userAddress:ComputedRef<UserAddress>=computed<UserAddress>(()=>orderInfo.value.userAddresses) as UserAddress
   const createOrderInfo = async (): Promise<void> => {
      const { result }: { result: Order } = await createOrderAPI();
      orderInfo.value = result;
   };


   return {
      orderInfo,
      goods,
      summary,
      userAddress,
      createOrderInfo,
   };


});

export default useOrderStore;
